<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>selenium_driverless.types.target &mdash; Selenium-Driverless 1.9.4 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css?v=80d5e7a1" />
      <link rel="stylesheet" type="text/css" href="../../../_static/css/theme.css?v=19f00094" />

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../../../_static/jquery.js?v=5d32c60e"></script>
        <script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js?v=1ac0efc4"></script>
        <script src="../../../_static/doctools.js?v=888ff710"></script>
        <script src="../../../_static/sphinx_highlight.js?v=4825356b"></script>
    <script src="../../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../../index.html" class="icon icon-home">
            Selenium-Driverless
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../api/By.html">By Element Locator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/Chrome.html">webdriver.Chrome</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/ChromeOptions.html">ChromeOptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/Context.html">Context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/Input.html">Input</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/RequestInterception.html">Request-Interception</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/Target.html">Target</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/WebELement.html">WebElement</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">Selenium-Driverless</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../index.html">Module code</a></li>
      <li class="breadcrumb-item active">selenium_driverless.types.target</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for selenium_driverless.types.target</h1><div class="highlight"><pre>
<span></span><span class="c1"># io</span>
<span class="kn">import</span> <span class="nn">asyncio</span>
<span class="kn">import</span> <span class="nn">base64</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">os.path</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">typing</span>
<span class="kn">from</span> <span class="nn">typing_extensions</span> <span class="kn">import</span> <span class="n">TypedDict</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">base64</span> <span class="kn">import</span> <span class="n">b64decode</span>
<span class="kn">import</span> <span class="nn">aiofiles</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span>
<span class="kn">import</span> <span class="nn">pathlib</span>
<span class="kn">import</span> <span class="nn">random</span>

<span class="kn">import</span> <span class="nn">websockets</span>
<span class="kn">from</span> <span class="nn">cdp_socket.exceptions</span> <span class="kn">import</span> <span class="n">CDPError</span>
<span class="kn">from</span> <span class="nn">cdp_socket.socket</span> <span class="kn">import</span> <span class="n">SingleCDPSocket</span>

<span class="c1"># pointer</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.sync.pointer</span> <span class="kn">import</span> <span class="n">Pointer</span> <span class="k">as</span> <span class="n">SyncPointer</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.input.pointer</span> <span class="kn">import</span> <span class="n">Pointer</span>
<span class="c1"># other</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.scripts.driver_utils</span> <span class="kn">import</span> <span class="n">get_targets</span><span class="p">,</span> <span class="n">get_target</span><span class="p">,</span> <span class="n">get_cookies</span><span class="p">,</span> <span class="n">get_cookie</span><span class="p">,</span> <span class="n">delete_cookie</span><span class="p">,</span> \
    <span class="n">delete_all_cookies</span><span class="p">,</span> <span class="n">add_cookie</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">safe_wrap_fut</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.deserialize</span> <span class="kn">import</span> <span class="n">StaleJSRemoteObjReference</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.webelement</span> <span class="kn">import</span> <span class="n">StaleElementReferenceException</span><span class="p">,</span> <span class="n">NoSuchElementException</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.sync.alert</span> <span class="kn">import</span> <span class="n">Alert</span> <span class="k">as</span> <span class="n">SyncAlert</span>
<span class="c1"># Alert</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.alert</span> <span class="kn">import</span> <span class="n">Alert</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.webelement</span> <span class="kn">import</span> <span class="n">WebElement</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.sync.webelement</span> <span class="kn">import</span> <span class="n">WebElement</span> <span class="k">as</span> <span class="n">SyncWebElement</span>

<span class="n">KEY_MAPPING</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyA&#39;</span><span class="p">,</span> <span class="mi">65</span><span class="p">),</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyB&#39;</span><span class="p">,</span> <span class="mi">66</span><span class="p">),</span> <span class="s1">&#39;c&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyC&#39;</span><span class="p">,</span> <span class="mi">67</span><span class="p">),</span> <span class="s1">&#39;d&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyD&#39;</span><span class="p">,</span> <span class="mi">68</span><span class="p">),</span> <span class="s1">&#39;e&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyE&#39;</span><span class="p">,</span> <span class="mi">69</span><span class="p">),</span>
    <span class="s1">&#39;f&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyF&#39;</span><span class="p">,</span> <span class="mi">70</span><span class="p">),</span> <span class="s1">&#39;g&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyG&#39;</span><span class="p">,</span> <span class="mi">71</span><span class="p">),</span> <span class="s1">&#39;h&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyH&#39;</span><span class="p">,</span> <span class="mi">72</span><span class="p">),</span> <span class="s1">&#39;i&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyI&#39;</span><span class="p">,</span> <span class="mi">73</span><span class="p">),</span> <span class="s1">&#39;j&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyJ&#39;</span><span class="p">,</span> <span class="mi">74</span><span class="p">),</span>
    <span class="s1">&#39;k&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyK&#39;</span><span class="p">,</span> <span class="mi">75</span><span class="p">),</span> <span class="s1">&#39;l&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyL&#39;</span><span class="p">,</span> <span class="mi">76</span><span class="p">),</span> <span class="s1">&#39;m&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyM&#39;</span><span class="p">,</span> <span class="mi">77</span><span class="p">),</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyN&#39;</span><span class="p">,</span> <span class="mi">78</span><span class="p">),</span> <span class="s1">&#39;o&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyO&#39;</span><span class="p">,</span> <span class="mi">79</span><span class="p">),</span>
    <span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyP&#39;</span><span class="p">,</span> <span class="mi">80</span><span class="p">),</span> <span class="s1">&#39;q&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyQ&#39;</span><span class="p">,</span> <span class="mi">81</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyR&#39;</span><span class="p">,</span> <span class="mi">82</span><span class="p">),</span> <span class="s1">&#39;s&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyS&#39;</span><span class="p">,</span> <span class="mi">83</span><span class="p">),</span> <span class="s1">&#39;t&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyT&#39;</span><span class="p">,</span> <span class="mi">84</span><span class="p">),</span>
    <span class="s1">&#39;u&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyU&#39;</span><span class="p">,</span> <span class="mi">85</span><span class="p">),</span> <span class="s1">&#39;v&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyV&#39;</span><span class="p">,</span> <span class="mi">86</span><span class="p">),</span> <span class="s1">&#39;w&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyW&#39;</span><span class="p">,</span> <span class="mi">87</span><span class="p">),</span> <span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyX&#39;</span><span class="p">,</span> <span class="mi">88</span><span class="p">),</span> <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyY&#39;</span><span class="p">,</span> <span class="mi">89</span><span class="p">),</span>
    <span class="s1">&#39;z&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyZ&#39;</span><span class="p">,</span> <span class="mi">90</span><span class="p">),</span> <span class="s1">&#39;A&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyA&#39;</span><span class="p">,</span> <span class="mi">65</span><span class="p">),</span> <span class="s1">&#39;B&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyB&#39;</span><span class="p">,</span> <span class="mi">66</span><span class="p">),</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyC&#39;</span><span class="p">,</span> <span class="mi">67</span><span class="p">),</span> <span class="s1">&#39;D&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyD&#39;</span><span class="p">,</span> <span class="mi">68</span><span class="p">),</span>
    <span class="s1">&#39;E&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyE&#39;</span><span class="p">,</span> <span class="mi">69</span><span class="p">),</span> <span class="s1">&#39;F&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyF&#39;</span><span class="p">,</span> <span class="mi">70</span><span class="p">),</span> <span class="s1">&#39;G&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyG&#39;</span><span class="p">,</span> <span class="mi">71</span><span class="p">),</span> <span class="s1">&#39;H&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyH&#39;</span><span class="p">,</span> <span class="mi">72</span><span class="p">),</span> <span class="s1">&#39;I&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyI&#39;</span><span class="p">,</span> <span class="mi">73</span><span class="p">),</span>
    <span class="s1">&#39;J&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyJ&#39;</span><span class="p">,</span> <span class="mi">74</span><span class="p">),</span> <span class="s1">&#39;K&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyK&#39;</span><span class="p">,</span> <span class="mi">75</span><span class="p">),</span> <span class="s1">&#39;L&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyL&#39;</span><span class="p">,</span> <span class="mi">76</span><span class="p">),</span> <span class="s1">&#39;M&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyM&#39;</span><span class="p">,</span> <span class="mi">77</span><span class="p">),</span> <span class="s1">&#39;N&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyN&#39;</span><span class="p">,</span> <span class="mi">78</span><span class="p">),</span>
    <span class="s1">&#39;O&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyO&#39;</span><span class="p">,</span> <span class="mi">79</span><span class="p">),</span> <span class="s1">&#39;P&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyP&#39;</span><span class="p">,</span> <span class="mi">80</span><span class="p">),</span> <span class="s1">&#39;Q&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyQ&#39;</span><span class="p">,</span> <span class="mi">81</span><span class="p">),</span> <span class="s1">&#39;R&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyR&#39;</span><span class="p">,</span> <span class="mi">82</span><span class="p">),</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyS&#39;</span><span class="p">,</span> <span class="mi">83</span><span class="p">),</span>
    <span class="s1">&#39;T&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyT&#39;</span><span class="p">,</span> <span class="mi">84</span><span class="p">),</span> <span class="s1">&#39;U&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyU&#39;</span><span class="p">,</span> <span class="mi">85</span><span class="p">),</span> <span class="s1">&#39;V&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyV&#39;</span><span class="p">,</span> <span class="mi">86</span><span class="p">),</span> <span class="s1">&#39;W&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyW&#39;</span><span class="p">,</span> <span class="mi">87</span><span class="p">),</span> <span class="s1">&#39;X&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyX&#39;</span><span class="p">,</span> <span class="mi">88</span><span class="p">),</span>
    <span class="s1">&#39;Y&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyY&#39;</span><span class="p">,</span> <span class="mi">89</span><span class="p">),</span> <span class="s1">&#39;Z&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;KeyZ&#39;</span><span class="p">,</span> <span class="mi">90</span><span class="p">),</span> <span class="s1">&#39;0&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit0&#39;</span><span class="p">,</span> <span class="mi">48</span><span class="p">),</span> <span class="s1">&#39;1&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit1&#39;</span><span class="p">,</span> <span class="mi">49</span><span class="p">),</span> <span class="s1">&#39;2&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit2&#39;</span><span class="p">,</span> <span class="mi">50</span><span class="p">),</span>
    <span class="s1">&#39;3&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit3&#39;</span><span class="p">,</span> <span class="mi">51</span><span class="p">),</span> <span class="s1">&#39;4&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit4&#39;</span><span class="p">,</span> <span class="mi">52</span><span class="p">),</span> <span class="s1">&#39;5&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit5&#39;</span><span class="p">,</span> <span class="mi">53</span><span class="p">),</span> <span class="s1">&#39;6&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit6&#39;</span><span class="p">,</span> <span class="mi">54</span><span class="p">),</span> <span class="s1">&#39;7&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit7&#39;</span><span class="p">,</span> <span class="mi">55</span><span class="p">),</span>
    <span class="s1">&#39;8&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit8&#39;</span><span class="p">,</span> <span class="mi">56</span><span class="p">),</span> <span class="s1">&#39;9&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit9&#39;</span><span class="p">,</span> <span class="mi">57</span><span class="p">),</span> <span class="s1">&#39;!&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit1&#39;</span><span class="p">,</span> <span class="mi">49</span><span class="p">),</span> <span class="s1">&#39;&quot;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Quote&#39;</span><span class="p">,</span> <span class="mi">222</span><span class="p">),</span> <span class="s1">&#39;#&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit3&#39;</span><span class="p">,</span> <span class="mi">51</span><span class="p">),</span>
    <span class="s1">&#39;$&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit4&#39;</span><span class="p">,</span> <span class="mi">52</span><span class="p">),</span> <span class="s1">&#39;%&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit5&#39;</span><span class="p">,</span> <span class="mi">53</span><span class="p">),</span> <span class="s1">&#39;&amp;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit7&#39;</span><span class="p">,</span> <span class="mi">55</span><span class="p">),</span> <span class="s2">&quot;&#39;&quot;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Quote&#39;</span><span class="p">,</span> <span class="mi">222</span><span class="p">),</span> <span class="s1">&#39;(&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit9&#39;</span><span class="p">,</span> <span class="mi">57</span><span class="p">),</span>
    <span class="s1">&#39;)&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit0&#39;</span><span class="p">,</span> <span class="mi">48</span><span class="p">),</span> <span class="s1">&#39;*&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit8&#39;</span><span class="p">,</span> <span class="mi">56</span><span class="p">),</span> <span class="s1">&#39;+&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Equal&#39;</span><span class="p">,</span> <span class="mi">187</span><span class="p">),</span> <span class="s1">&#39;,&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Comma&#39;</span><span class="p">,</span> <span class="mi">188</span><span class="p">),</span> <span class="s1">&#39;-&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Minus&#39;</span><span class="p">,</span> <span class="mi">189</span><span class="p">),</span>
    <span class="s1">&#39;.&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Period&#39;</span><span class="p">,</span> <span class="mi">190</span><span class="p">),</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Slash&#39;</span><span class="p">,</span> <span class="mi">191</span><span class="p">),</span> <span class="s1">&#39;:&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Semicolon&#39;</span><span class="p">,</span> <span class="mi">186</span><span class="p">),</span> <span class="s1">&#39;;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Semicolon&#39;</span><span class="p">,</span> <span class="mi">186</span><span class="p">),</span>
    <span class="s1">&#39;&lt;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Comma&#39;</span><span class="p">,</span> <span class="mi">188</span><span class="p">),</span>
    <span class="s1">&#39;=&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Equal&#39;</span><span class="p">,</span> <span class="mi">187</span><span class="p">),</span> <span class="s1">&#39;&gt;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Period&#39;</span><span class="p">,</span> <span class="mi">190</span><span class="p">),</span> <span class="s1">&#39;?&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Slash&#39;</span><span class="p">,</span> <span class="mi">191</span><span class="p">),</span> <span class="s1">&#39;@&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit2&#39;</span><span class="p">,</span> <span class="mi">50</span><span class="p">),</span>
    <span class="s1">&#39;[&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;BracketLeft&#39;</span><span class="p">,</span> <span class="mi">219</span><span class="p">),</span>
    <span class="s1">&#39;</span><span class="se">\\</span><span class="s1">&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Backslash&#39;</span><span class="p">,</span> <span class="mi">220</span><span class="p">),</span> <span class="s1">&#39;]&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;BracketRight&#39;</span><span class="p">,</span> <span class="mi">221</span><span class="p">),</span> <span class="s1">&#39;^&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Digit6&#39;</span><span class="p">,</span> <span class="mi">54</span><span class="p">),</span> <span class="s1">&#39;_&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Minus&#39;</span><span class="p">,</span> <span class="mi">189</span><span class="p">),</span>
    <span class="s1">&#39;`&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Backquote&#39;</span><span class="p">,</span> <span class="mi">192</span><span class="p">),</span>
    <span class="s1">&#39;{&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;BracketLeft&#39;</span><span class="p">,</span> <span class="mi">219</span><span class="p">),</span> <span class="s1">&#39;|&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Backslash&#39;</span><span class="p">,</span> <span class="mi">220</span><span class="p">),</span> <span class="s1">&#39;}&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;BracketRight&#39;</span><span class="p">,</span> <span class="mi">221</span><span class="p">),</span> <span class="s1">&#39;~&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Backquote&#39;</span><span class="p">,</span> <span class="mi">192</span><span class="p">),</span>
    <span class="s1">&#39; &#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Space&#39;</span><span class="p">,</span> <span class="mi">32</span><span class="p">),</span> <span class="s1">&#39;</span><span class="se">\r</span><span class="s1">&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;Enter&#39;</span><span class="p">,</span> <span class="mi">13</span><span class="p">)</span>
<span class="p">}</span>

<span class="n">SHIFT_KEY_NEEDED</span> <span class="o">=</span> <span class="s1">&#39;~!@#$%^&amp;*()_+</span><span class="si">{}</span><span class="s1">|:&quot;&lt;&gt;?&#39;</span>


<span class="k">class</span> <span class="nc">NoSuchIframe</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="n">reference</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">WebElement</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reference</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">WebElement</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span> <span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reference</span> <span class="o">=</span> <span class="n">reference</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>


<div class="viewcode-block" id="Target"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target">[docs]</a><span class="k">class</span> <span class="nc">Target</span><span class="p">:</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;the Target class</span>

<span class="sd">    Usually a tab, (cors-)iframe, WebWorker etc.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># noinspection PyShadowingBuiltins</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">host</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">driver</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="n">is_remote</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
                 <span class="n">loop</span><span class="p">:</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">AbstractEventLoop</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">,</span>
                 <span class="nb">type</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">start_socket</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">**</span> <span class="mi">20</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="kn">from</span> <span class="nn">selenium_driverless.types.context</span> <span class="kn">import</span> <span class="n">Context</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parent_target</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_context</span><span class="p">:</span> <span class="n">Context</span> <span class="o">=</span> <span class="n">context</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_window_id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_pointer</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_page_enabled</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_dom_enabled</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span> <span class="o">=</span> <span class="n">max_ws_size</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_global_this_</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_alert</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_targets</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_socket</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id_</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_exec_context_id_</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_targets</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Target</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span> <span class="o">=</span> <span class="n">is_remote</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_host</span> <span class="o">=</span> <span class="n">host</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="n">target_id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_context_id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_type</span> <span class="o">=</span> <span class="nb">type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">=</span> <span class="n">timeout</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span> <span class="o">=</span> <span class="n">loop</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_start_socket</span> <span class="o">=</span> <span class="n">start_socket</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_on_closed_</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_driver</span> <span class="o">=</span> <span class="n">driver</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_send_key_lock</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="sa">f</span><span class="s1">&#39;&lt;</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__module__</span><span class="si">}</span><span class="s1">.</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s1"> (target_id=&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="si">}</span><span class="s1">&quot;, host=&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="si">}</span><span class="s1">&quot;)&gt;&#39;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_id</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">browser_context_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_context_id</span><span class="p">:</span>
            <span class="n">info</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
            <span class="k">return</span> <span class="n">info</span><span class="o">.</span><span class="n">browser_context_id</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_context_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">base_target</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_driver</span><span class="o">.</span><span class="n">base_target</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">socket</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">SingleCDPSocket</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;the cdp-socket for the connection&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_socket</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Target</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">other</span><span class="o">.</span><span class="n">socket</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span>
        <span class="k">return</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">async</span> <span class="k">def</span> <span class="fm">__aexit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_val</span><span class="p">,</span> <span class="n">exc_tb</span><span class="p">):</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_val</span><span class="p">,</span> <span class="n">exc_tb</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="k">async</span> <span class="k">def</span> <span class="fm">__aenter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># doesn&#39;t do anything (start_socket=False)</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="fm">__await__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_start_socket</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span><span class="o">.</span><span class="fm">__await__</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># doesn&#39;t do anything (start_socket=False)</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__aenter__</span><span class="p">()</span><span class="o">.</span><span class="fm">__await__</span><span class="p">()</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_init</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_socket</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_socket</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SingleCDPSocket</span><span class="p">(</span><span class="n">websock_url</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;ws://</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="si">}</span><span class="s1">/devtools/page/</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_id</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                                 <span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">max_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_pointer</span> <span class="o">=</span> <span class="n">SyncPointer</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_pointer</span> <span class="o">=</span> <span class="n">Pointer</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>

            <span class="k">def</span> <span class="nf">set_alert</span><span class="p">(</span><span class="n">alert</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_alert</span> <span class="o">=</span> <span class="n">alert</span>

            <span class="c1"># noinspection PyUnusedLocal</span>
            <span class="k">def</span> <span class="nf">remove_alert</span><span class="p">(</span><span class="n">alert</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_alert</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_cdp_listener</span><span class="p">(</span><span class="s2">&quot;Page.javascriptDialogOpening&quot;</span><span class="p">,</span> <span class="n">set_alert</span><span class="p">)</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_cdp_listener</span><span class="p">(</span><span class="s2">&quot;Page.javascriptDialogClosed&quot;</span><span class="p">,</span> <span class="n">remove_alert</span><span class="p">)</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_cdp_listener</span><span class="p">(</span><span class="s2">&quot;Page.loadEventFired&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">)</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_cdp_listener</span><span class="p">(</span><span class="s2">&quot;Page.windowOpen&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">on_closed</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_on_closed</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">_on_closed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">on_closed</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_closed_</span>

    <span class="c1"># noinspection PyUnusedLocals,PyUnusedLocal</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">_on_loaded</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_global_this_</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id_</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_exec_context_id_</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_alert</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">5</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_page_enabled</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.enable&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
            <span class="n">alert</span> <span class="o">=</span> <span class="n">SyncAlert</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">alert</span> <span class="o">=</span> <span class="k">await</span> <span class="n">Alert</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">alert</span>

<div class="viewcode-block" id="Target.get_targets_for_iframes"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_targets_for_iframes">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_targets_for_iframes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iframes</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        find targets for a list of iframes</span>

<span class="sd">        :param iframes: iframes to find targets for</span>

<span class="sd">        .. warning::</span>

<span class="sd">            only CORS iframes have its own target,</span>
<span class="sd">            you might use :func:`WebElement.content_document &lt;selenium_driverless.types.webelement.WebElement.content_document&gt;`</span>
<span class="sd">            instead</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">iframes</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Expected WebElements, but got</span><span class="si">{</span><span class="n">iframes</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

        <span class="k">async</span> <span class="k">def</span> <span class="nf">target_getter</span><span class="p">(</span><span class="n">target_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">**</span> <span class="mi">20</span><span class="p">):</span>
            <span class="k">return</span> <span class="k">await</span> <span class="n">get_target</span><span class="p">(</span><span class="n">target_id</span><span class="o">=</span><span class="n">target_id</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">is_remote</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">,</span>
                                    <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="o">=</span><span class="n">max_ws_size</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_driver</span><span class="p">,</span>
                                    <span class="n">context</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_context</span><span class="p">)</span>

        <span class="n">_targets</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_targets</span><span class="p">(</span><span class="n">cdp_exec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">,</span> <span class="n">target_getter</span><span class="o">=</span><span class="n">target_getter</span><span class="p">,</span>
                                     <span class="n">_type</span><span class="o">=</span><span class="s2">&quot;iframe&quot;</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_context_id</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>
        <span class="n">targets</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">for</span> <span class="n">targetinfo</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">_targets</span><span class="o">.</span><span class="n">values</span><span class="p">()):</span>
            <span class="c1"># iterate over iframes</span>
            <span class="n">target</span> <span class="o">=</span> <span class="n">targetinfo</span><span class="o">.</span><span class="n">Target</span>
            <span class="n">base_frame</span> <span class="o">=</span> <span class="k">await</span> <span class="n">target</span><span class="o">.</span><span class="n">base_frame</span>

            <span class="c1">#  check if iframe element is within iframes to search</span>
            <span class="k">for</span> <span class="n">iframe</span> <span class="ow">in</span> <span class="n">iframes</span><span class="p">:</span>
                <span class="n">tag_name</span> <span class="o">=</span> <span class="k">await</span> <span class="n">iframe</span><span class="o">.</span><span class="n">tag_name</span>
                <span class="k">if</span> <span class="n">tag_name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">&quot;IFRAME&quot;</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">NoSuchIframe</span><span class="p">(</span><span class="n">iframe</span><span class="p">,</span> <span class="s2">&quot;element isn&#39;t a iframe&quot;</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">iframe</span><span class="o">.</span><span class="n">obj_id</span>
                <span class="n">iframe_frame_id</span> <span class="o">=</span> <span class="k">await</span> <span class="n">iframe</span><span class="o">.</span><span class="n">__frame_id__</span>
                <span class="k">if</span> <span class="n">base_frame</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">iframe_frame_id</span><span class="p">:</span>
                    <span class="k">if</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;iframe&quot;</span><span class="p">:</span>
                        <span class="n">target</span><span class="o">.</span><span class="n">_parent_target</span> <span class="o">=</span> <span class="bp">self</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">target</span><span class="o">.</span><span class="n">_base_target</span> <span class="o">=</span> <span class="bp">self</span>
                    <span class="n">targets</span><span class="p">[</span><span class="n">target</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">target</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">targets</span><span class="o">.</span><span class="n">values</span><span class="p">())</span></div>

<div class="viewcode-block" id="Target.get_target_for_iframe"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_target_for_iframe">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_target_for_iframe</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iframe</span><span class="p">:</span> <span class="n">WebElement</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        find a target for an iframe</span>

<span class="sd">        :param iframe: iframe to find target for</span>

<span class="sd">        .. warning::</span>

<span class="sd">            only CORS iframes have its own target,</span>
<span class="sd">            you might use :func:`WebElement.content_document &lt;selenium_driverless.types.webelement.WebElement.content_document&gt;`</span>
<span class="sd">            instead</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">targets</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_targets_for_iframes</span><span class="p">([</span><span class="n">iframe</span><span class="p">])</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">targets</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">NoSuchIframe</span><span class="p">(</span><span class="n">iframe</span><span class="p">,</span> <span class="s2">&quot;no target for iframe found&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">targets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Target.wait_download"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.wait_download">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">wait_download</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        wait for a download on the current tab</span>

<span class="sd">        returns something like</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            {</span>
<span class="sd">                &quot;frameId&quot;: &quot;2D543B5E8B14945B280C537A4882A695&quot;,</span>
<span class="sd">                &quot;guid&quot;: &quot;c91df4d5-9b45-4962-84df-3749bd3f926d&quot;,</span>
<span class="sd">                &quot;url&quot;: &quot;https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf&quot;,</span>
<span class="sd">                &quot;suggestedFilename&quot;: &quot;dummy.pdf&quot;,</span>

<span class="sd">                # only if options.downloads_dir specified</span>
<span class="sd">                &quot;guid_file&quot;: &quot;D:\\System\\AppData\\PyCharm\\scratches\\downloads\\c91df4d5-9b45-4962-84df-3749bd3f926d&quot;</span>
<span class="sd">            }</span>

<span class="sd">        :param timeout: time in seconds to wait for a download</span>

<span class="sd">        .. warning::</span>
<span class="sd">            downloads from iframes not supported yet</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># todo: support downloads from iframes</span>
        <span class="k">async</span> <span class="k">def</span> <span class="nf">_wait_download</span><span class="p">():</span>
            <span class="n">base_frame</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_frame</span>
            <span class="n">_id</span> <span class="o">=</span> <span class="n">base_frame</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;id&quot;</span><span class="p">)</span>
            <span class="n">_dir</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_context</span><span class="o">.</span><span class="n">downloads_dir</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">async</span> <span class="k">for</span> <span class="n">data</span> <span class="ow">in</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_target</span><span class="o">.</span><span class="n">get_cdp_event_iter</span><span class="p">(</span><span class="s2">&quot;Browser.downloadWillBegin&quot;</span><span class="p">):</span>
                <span class="n">base_frame</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_frame</span>
                <span class="n">curr_id</span> <span class="o">=</span> <span class="n">base_frame</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;id&quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;frameId&quot;</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="n">_id</span><span class="p">,</span> <span class="n">curr_id</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">_dir</span><span class="p">:</span>
                        <span class="n">guid_file</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">_dir</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;guid&quot;</span><span class="p">]))</span>
                        <span class="n">named_file</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">_dir</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="s2">&quot;suggestedFilename&quot;</span><span class="p">))</span>
                        <span class="n">data</span><span class="p">[</span><span class="s2">&quot;guid_file&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">guid_file</span>
                        <span class="n">data</span><span class="p">[</span><span class="s2">&quot;named_file&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">named_file</span>
                        <span class="k">while</span> <span class="ow">not</span> <span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">guid_file</span><span class="p">)</span> <span class="ow">or</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">named_file</span><span class="p">)):</span>
                            <span class="c1"># wait for file to exist</span>
                            <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
                    <span class="k">return</span> <span class="n">data</span>

        <span class="k">return</span> <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">wait_for</span><span class="p">(</span><span class="n">_wait_download</span><span class="p">(),</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

    <span class="c1"># noinspection PyUnboundLocalVariable,PyProtectedMember</span>
<div class="viewcode-block" id="Target.get"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">referrer</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">wait_load</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Loads a web page</span>

<span class="sd">        :param url: the url to load.</span>
<span class="sd">        :param referrer: the referrer to load the page with</span>
<span class="sd">        :param wait_load: whether to wait for the webpage to load</span>
<span class="sd">        :param timeout: the maximum time in seconds for waiting on load</span>

<span class="sd">        returns the same as :func:`Target.wait_download &lt;selenium_driverless.types.target.Target.wait_download&gt;` if the url initiates a download</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">url</span> <span class="o">==</span> <span class="s2">&quot;about:blank&quot;</span><span class="p">:</span>
            <span class="n">wait_load</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="s2">&quot;#&quot;</span> <span class="ow">in</span> <span class="n">url</span><span class="p">:</span>
            <span class="c1"># thanks to https://github.com/kaliiiiiiiiii/Selenium-Driverless/issues/139#issuecomment-1877197974</span>
            <span class="n">current_url_base</span> <span class="o">=</span> <span class="p">(</span><span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_url</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">url</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;#&quot;</span><span class="p">:</span>
                <span class="c1"># allow to navigate only by fragment ID of the current url</span>
                <span class="n">url</span> <span class="o">=</span> <span class="n">current_url_base</span> <span class="o">+</span> <span class="n">url</span>
                <span class="n">wait_load</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">current_url_base</span><span class="p">:</span>
                <span class="n">wait_load</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">if</span> <span class="n">wait_load</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_page_enabled</span><span class="p">:</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.enable&quot;</span><span class="p">)</span>

            <span class="c1"># wait for download or loadEventFired</span>
            <span class="n">wait</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">ensure_future</span><span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span>
                <span class="n">safe_wrap_fut</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wait_for_cdp</span><span class="p">(</span><span class="s2">&quot;Page.loadEventFired&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">)),</span>
                <span class="n">safe_wrap_fut</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wait_download</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">))</span>
            <span class="p">],</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">return_when</span><span class="o">=</span><span class="n">asyncio</span><span class="o">.</span><span class="n">FIRST_COMPLETED</span><span class="p">))</span>

            <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>  <span class="c1"># ensure listening for events has already started</span>

        <span class="c1"># send navigate cmd</span>
        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;url&quot;</span><span class="p">:</span> <span class="n">url</span><span class="p">,</span> <span class="s2">&quot;transitionType&quot;</span><span class="p">:</span> <span class="s2">&quot;link&quot;</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">referrer</span><span class="p">:</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;referrer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">referrer</span>
        <span class="n">get</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">ensure_future</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.navigate&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">wait_load</span><span class="p">:</span>
            <span class="n">done</span><span class="p">,</span> <span class="n">pending</span> <span class="o">=</span> <span class="k">await</span> <span class="n">wait</span>
            <span class="n">pending</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">done</span><span class="p">:</span>
                <span class="n">pending</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="k">await</span> <span class="n">get</span>  <span class="c1"># ensure get is awaited in every case</span>
                <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">e</span>
                <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;page: &quot;</span><span class="si">{</span><span class="n">url</span><span class="si">}</span><span class="s1">&quot; didn</span><span class="se">\&#39;</span><span class="s1">t load within timeout of </span><span class="si">{</span><span class="n">timeout</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">result</span> <span class="o">=</span> <span class="n">done</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">.</span><span class="n">result</span><span class="p">()</span>  <span class="c1"># data of the event waited for</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">await</span> <span class="n">get</span>  <span class="c1"># wait for navigate cmd response</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">e</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">result</span></div>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_global_this</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">context_id</span><span class="p">:</span>
            <span class="n">context_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_exec_context_id_</span>
        <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this_</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">context_id</span><span class="p">))</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.types.deserialize</span> <span class="kn">import</span> <span class="n">JSRemoteObj</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.types</span> <span class="kn">import</span> <span class="n">JSEvalException</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;expression&quot;</span><span class="p">:</span> <span class="s2">&quot;globalThis&quot;</span><span class="p">,</span>
                    <span class="s2">&quot;serializationOptions&quot;</span><span class="p">:</span> <span class="p">{</span>
                        <span class="s2">&quot;serialization&quot;</span><span class="p">:</span> <span class="s2">&quot;idOnly&quot;</span><span class="p">}}</span>
            <span class="k">if</span> <span class="n">context_id</span><span class="p">:</span>
                <span class="n">args</span><span class="p">[</span><span class="s2">&quot;contextId&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">context_id</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Runtime.evaluate&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32000</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s1">&#39;Cannot find context with specified id&#39;</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">(</span><span class="s2">&quot;GlobalThis&quot;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">e</span>

            <span class="k">if</span> <span class="s2">&quot;exceptionDetails&quot;</span> <span class="ow">in</span> <span class="n">res</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="k">raise</span> <span class="n">JSEvalException</span><span class="p">(</span><span class="n">res</span><span class="p">[</span><span class="s2">&quot;exceptionDetails&quot;</span><span class="p">])</span>
            <span class="n">obj_id</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;result&quot;</span><span class="p">][</span><span class="s1">&#39;objectId&#39;</span><span class="p">]</span>

            <span class="n">base_frame</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_frame</span>
            <span class="c1"># target can have no frames at all</span>
            <span class="n">frame_id</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="n">base_frame</span><span class="p">:</span>
                <span class="n">frame_id</span> <span class="o">=</span> <span class="n">base_frame</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;id&quot;</span><span class="p">)</span>

            <span class="c1"># noinspection PyUnresolvedReferences</span>
            <span class="n">obj</span> <span class="o">=</span> <span class="n">JSRemoteObj</span><span class="p">(</span><span class="n">obj_id</span><span class="o">=</span><span class="n">obj_id</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">isolated_exec_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                              <span class="n">frame_id</span><span class="o">=</span><span class="n">frame_id</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">context_id</span><span class="p">:</span>
                <span class="n">context_id</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">__context_id__</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_exec_context_id_</span> <span class="o">=</span> <span class="n">context_id</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_global_this_</span><span class="p">[</span><span class="n">context_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">obj</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this_</span><span class="p">[</span><span class="n">context_id</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">_isolated_context_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
        <span class="n">doc</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">doc</span><span class="o">.</span><span class="n">__isolated_exec_id__</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">pointer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Pointer</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;the :class:`Pointer &lt;selenium_driverless.input.pointer.Pointer&gt;` for this target&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pointer</span>

<div class="viewcode-block" id="Target.send_keys"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.send_keys">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">send_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">allow_not_on_mapping</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        send text &amp; keys to the target</span>

<span class="sd">        :param text: the text to send to the target</span>
<span class="sd">        :param allow_not_on_mapping: allow keys which aren&#39;t int the keyboard mapping</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">async</span> <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">_send_key_lock</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">letter</span> <span class="ow">in</span> <span class="n">text</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">letter</span> <span class="ow">in</span> <span class="n">KEY_MAPPING</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">letter</span> <span class="o">==</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">:</span>
                        <span class="n">letter</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\r</span><span class="s2">&quot;</span>
                    <span class="n">key_code</span><span class="p">,</span> <span class="n">virtual_key_code</span> <span class="o">=</span> <span class="n">KEY_MAPPING</span><span class="p">[</span><span class="n">letter</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">allow_not_on_mapping</span><span class="p">:</span>
                    <span class="n">key_code</span><span class="p">,</span> <span class="n">virtual_key_code</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;letter:</span><span class="si">{</span><span class="n">letter</span><span class="si">}</span><span class="s2"> not in keyboard mapping&quot;</span><span class="p">)</span>

                <span class="c1"># Determine if a shift key is needed</span>
                <span class="n">shift_pressed</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">if</span> <span class="n">letter</span><span class="o">.</span><span class="n">isupper</span><span class="p">()</span> <span class="ow">or</span> <span class="n">letter</span> <span class="ow">in</span> <span class="n">SHIFT_KEY_NEEDED</span><span class="p">:</span>
                    <span class="n">shift_pressed</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Input.dispatchKeyEvent&quot;</span><span class="p">,</span> <span class="p">{</span>
                        <span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;keyDown&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;code&quot;</span><span class="p">:</span> <span class="s2">&quot;ShiftLeft&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;windowsVirtualKeyCode&quot;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                        <span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;Shift&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;modifiers&quot;</span><span class="p">:</span> <span class="mi">8</span> <span class="k">if</span> <span class="n">shift_pressed</span> <span class="k">else</span> <span class="mi">0</span>
                    <span class="p">})</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">))</span>  <span class="c1"># Simulate human typing speed</span>

                <span class="n">key_event</span> <span class="o">=</span> <span class="p">{</span>
                    <span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;keyDown&quot;</span><span class="p">,</span>
                    <span class="s2">&quot;code&quot;</span><span class="p">:</span> <span class="n">key_code</span><span class="p">,</span>
                    <span class="s2">&quot;windowsVirtualKeyCode&quot;</span><span class="p">:</span> <span class="n">virtual_key_code</span><span class="p">,</span>
                    <span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="n">letter</span><span class="p">,</span>
                    <span class="s2">&quot;modifiers&quot;</span><span class="p">:</span> <span class="mi">8</span> <span class="k">if</span> <span class="n">shift_pressed</span> <span class="k">else</span> <span class="mi">0</span>
                <span class="p">}</span>

                <span class="c1"># Send keydown event</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Input.dispatchKeyEvent&quot;</span><span class="p">,</span> <span class="n">key_event</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">))</span>

                <span class="c1"># Simulate key press for the actual character</span>
                <span class="n">key_event</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;char&quot;</span>
                <span class="n">key_event</span><span class="p">[</span><span class="s2">&quot;text&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">letter</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Input.dispatchKeyEvent&quot;</span><span class="p">,</span> <span class="n">key_event</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">))</span>
                <span class="k">del</span> <span class="n">key_event</span><span class="p">[</span><span class="s1">&#39;text&#39;</span><span class="p">]</span>

                <span class="c1"># Simulate key release</span>
                <span class="n">key_event</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;keyUp&quot;</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Input.dispatchKeyEvent&quot;</span><span class="p">,</span> <span class="n">key_event</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">))</span>

                <span class="c1"># Release the shift key if it was pressed</span>
                <span class="k">if</span> <span class="n">shift_pressed</span><span class="p">:</span>
                    <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Input.dispatchKeyEvent&quot;</span><span class="p">,</span> <span class="p">{</span>
                        <span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;keyUp&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;code&quot;</span><span class="p">:</span> <span class="s2">&quot;ShiftLeft&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;windowsVirtualKeyCode&quot;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
                        <span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;Shift&quot;</span><span class="p">,</span>
                        <span class="s2">&quot;modifiers&quot;</span><span class="p">:</span> <span class="mi">0</span>
                    <span class="p">})</span>
                    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">))</span>  <span class="c1"># Simulate human typing speed</span></div>

<div class="viewcode-block" id="Target.execute_raw_script"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.execute_raw_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_raw_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">await_res</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                                 <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                                 <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes a JavaScript on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            function(...arguments){return document}</span>

<span class="sd">        :param script: the script as a string</span>
<span class="sd">        :param args: the argument which are passed to the function. Those can be either json-serializable or a RemoteObject such as WebELement</span>
<span class="sd">        :param await_res: whether to await the function or the return value of it</span>
<span class="sd">        :param serialization: can be one of ``deep``, ``json``, ``idOnly``</span>
<span class="sd">        :param max_depth: The maximum depth objects get serialized.</span>
<span class="sd">        :param timeout: the maximum time to wait for the execution to complete</span>
<span class="sd">        :param execution_context_id: the execution context id to run the JavaScript in. Exclusive with unique_context</span>
<span class="sd">        :param unique_context: whether to use a isolated context to run the Script in.</span>

<span class="sd">        see `Runtime.callFunctionOn &lt;https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-callFunctionOn&gt;`_</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">execution_context_id</span> <span class="ow">and</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;got execution_context_id and unique_context=True, defaulting to execution_context_id&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">execution_context_id</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id</span>

        <span class="k">if</span> <span class="n">timeout</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>

        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="n">exc</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">global_this</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this</span><span class="p">(</span><span class="n">execution_context_id</span><span class="p">)</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="n">global_this</span><span class="o">.</span><span class="n">__exec_raw__</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">await_res</span><span class="o">=</span><span class="n">await_res</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                     <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                     <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">StaleJSRemoteObjReference</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="n">exc</span> <span class="o">=</span> <span class="n">e</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">res</span>
        <span class="k">if</span> <span class="n">exc</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">exc</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Couldn&#39;t execute script due to stale reference within </span><span class="si">{</span><span class="n">timeout</span><span class="si">}</span><span class="s2"> s, &quot;</span>
                                       <span class="sa">f</span><span class="s2">&quot;possibly due to a reload loop&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.execute_script"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.execute_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                             <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                             <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript synchronously on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            return document</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">execution_context_id</span> <span class="ow">and</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;got execution_context_id and unique_context=True, defaulting to execution_context_id&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">execution_context_id</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id</span>
        <span class="k">if</span> <span class="n">timeout</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>

        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="n">global_this</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this</span><span class="p">(</span><span class="n">execution_context_id</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="n">global_this</span><span class="o">.</span><span class="n">__exec__</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                 <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                 <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                 <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">res</span>
            <span class="k">except</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">:</span>
                <span class="k">pass</span>
        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t execute script, possibly due to a reload loop&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.execute_async_script"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.execute_async_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_async_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                                   <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                                   <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript asynchronously on ``GlobalThis``</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            resolve = arguments[arguments.length-1]</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">execution_context_id</span> <span class="ow">and</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;got execution_context_id and unique_context=True, defaulting to execution_context_id&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">execution_context_id</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id</span>
        <span class="k">if</span> <span class="n">timeout</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>

        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="n">global_this</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this</span><span class="p">(</span><span class="n">execution_context_id</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="n">global_this</span><span class="o">.</span><span class="n">__exec_async__</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                       <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                       <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                       <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">res</span>
            <span class="k">except</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">:</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t execute script, possibly due to a reload loop&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.eval_async"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.eval_async">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">eval_async</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                         <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                         <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript asynchronously on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            res = await fetch(&quot;https://httpbin.org/get&quot;);</span>
<span class="sd">            // mind CORS!</span>
<span class="sd">            json = await res.json()</span>
<span class="sd">            return json</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">execution_context_id</span> <span class="ow">and</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;got execution_context_id and unique_context=True, defaulting to execution_context_id&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">unique_context</span><span class="p">:</span>
            <span class="n">execution_context_id</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_isolated_context_id</span>
        <span class="k">if</span> <span class="n">timeout</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>

        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="n">global_this</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_global_this</span><span class="p">(</span><span class="n">execution_context_id</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="n">global_this</span><span class="o">.</span><span class="n">__eval_async__</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                       <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                       <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                       <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">res</span>
            <span class="k">except</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">:</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t execute script, possibly due to a reload loop&quot;</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">current_url</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the URL of the current page.</span>

<span class="sd">        :Usage:</span>
<span class="sd">            ::</span>

<span class="sd">                target.current_url</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
        <span class="k">return</span> <span class="n">target</span><span class="o">.</span><span class="n">url</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">page_source</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the HTML of the current page.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="n">timeout</span> <span class="o">=</span> <span class="mi">10</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">elem</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>
                <span class="k">return</span> <span class="k">await</span> <span class="n">elem</span><span class="o">.</span><span class="n">source</span>
            <span class="k">except</span> <span class="n">StaleElementReferenceException</span><span class="p">:</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span>
        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span>
            <span class="sa">f</span><span class="s2">&quot;Couldn&#39;t get page source within </span><span class="si">{</span><span class="n">timeout</span><span class="si">}</span><span class="s2"> seconds, possibly due to a reload loop&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="Target.close"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.close">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Closes the current window.</span>

<span class="sd">        :Usage:</span>
<span class="sd">            ::</span>

<span class="sd">                target.close()</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Target.closeTarget&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;targetId&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">},</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_socket</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">except</span> <span class="n">websockets</span><span class="o">.</span><span class="n">ConnectionClosedError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">except</span> <span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">,</span> <span class="ne">TimeoutError</span><span class="p">):</span>
            <span class="k">pass</span></div>

<div class="viewcode-block" id="Target.focus"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.focus">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">focus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">activate</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        emulates Focus of the target</span>

<span class="sd">        :param activate: whether to bring the window to the front</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">activate</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">activate</span><span class="p">()</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Emulation.setFocusEmulationEnabled&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span>
        <span class="k">except</span> <span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32601</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s2">&quot;&#39;Emulation.setFocusEmulationEnabled&#39; wasn&#39;t found&quot;</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">e</span></div>

<div class="viewcode-block" id="Target.unfocus"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.unfocus">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">unfocus</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        disables focus emulation for the target</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Emulation.setFocusEmulationEnabled&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">})</span>
        <span class="k">except</span> <span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32601</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s2">&quot;&#39;Target.activateTarget&#39; wasn&#39;t found&quot;</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">raise</span> <span class="n">e</span></div>

<div class="viewcode-block" id="Target.activate"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.activate">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">activate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        brings the window to the front</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Target.activateTarget&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;targetId&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
        <span class="k">except</span> <span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32601</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s2">&quot;&#39;Target.activateTarget&#39; wasn&#39;t found&quot;</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="k">raise</span> <span class="n">e</span></div>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Target.getTargetInfo&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;targetId&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">TargetInfo</span><span class="p">(</span><span class="n">res</span><span class="p">[</span><span class="s2">&quot;targetInfo&quot;</span><span class="p">],</span> <span class="bp">self</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">frame_tree</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.getFrameTree&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;frameTree&quot;</span><span class="p">]</span>
        <span class="k">except</span> <span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32601</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s2">&quot;&#39;Page.getFrameTree&#39; wasn&#39;t found&quot;</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">e</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">base_frame</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">frame_tree</span>
        <span class="k">if</span> <span class="n">res</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;frame&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_type</span><span class="p">:</span>
            <span class="n">info</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_type</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">type</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_type</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">title</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="c1"># noinspection GrazieInspection</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns the title of the target&quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
        <span class="k">return</span> <span class="n">target</span><span class="o">.</span><span class="n">title</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="n">info</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">info</span>
        <span class="k">return</span> <span class="n">info</span><span class="o">.</span><span class="n">url</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">window_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_window_id</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.getWindowForTarget&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;targetId&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_window_id</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;windowId&quot;</span><span class="p">]</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_window_id</span>

<div class="viewcode-block" id="Target.print_page"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.print_page">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">print_page</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Takes PDF of the current page.</span>

<span class="sd">        The target makes the best effort to return a PDF based on the</span>
<span class="sd">        provided parameters.</span>

<span class="sd">        returns Base64-encoded pdf data as a string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">page</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.printToPDF&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">page</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">]</span></div>

<div class="viewcode-block" id="Target.get_history"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_history">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_history</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">TypedDict</span><span class="p">(</span><span class="s1">&#39;NavigationHistory&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;currentIndex&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="s1">&#39;entries&#39;</span><span class="p">:</span> <span class="nb">list</span><span class="p">}):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;returns the history data</span>

<span class="sd">        see `Page.getNavigationHistory &lt;https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-getNavigationHistory&gt;`__</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.getNavigationHistory&quot;</span><span class="p">)</span></div>

    <span class="c1"># Navigation</span>
<div class="viewcode-block" id="Target.back"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.back">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">back</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Goes one step backward in the browser history.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">history</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_history</span><span class="p">()</span>
        <span class="n">entry</span> <span class="o">=</span> <span class="n">history</span><span class="p">[</span><span class="s2">&quot;entries&quot;</span><span class="p">][</span><span class="n">history</span><span class="p">[</span><span class="s1">&#39;currentIndex&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.navigateToHistoryEntry&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;entryId&quot;</span><span class="p">:</span> <span class="n">entry</span><span class="p">})</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span></div>

<div class="viewcode-block" id="Target.forward"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.forward">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Goes one step forward in the browser history.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">history</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_history</span><span class="p">()</span>
        <span class="n">entry</span> <span class="o">=</span> <span class="n">history</span><span class="p">[</span><span class="s2">&quot;entries&quot;</span><span class="p">][</span><span class="n">history</span><span class="p">[</span><span class="s2">&quot;currentIndex&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">][</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.navigateToHistoryEntry&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;entryId&quot;</span><span class="p">:</span> <span class="n">entry</span><span class="p">})</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span></div>

<div class="viewcode-block" id="Target.refresh"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.refresh">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">refresh</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Refreshes the page.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.reload&quot;</span><span class="p">)</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span></div>

    <span class="c1"># Options</span>
<div class="viewcode-block" id="Target.get_cookies"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_cookies">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="nb">dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns a set of dictionaries, corresponding to cookies visible in</span>
<span class="sd">        the current context.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">get_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.get_cookie"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Get a single cookie by name. Returns the cookie if found, None if</span>
<span class="sd">        not.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">get_cookie</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.delete_cookie"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.delete_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">domain</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">path</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Deletes a single cookie with the given name.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">delete_cookie</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">domain</span><span class="o">=</span><span class="n">domain</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.delete_all_cookies"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.delete_all_cookies">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_all_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Delete all cookies in the scope of the context.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">delete_all_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>

    <span class="c1"># noinspection GrazieInspection</span>
<div class="viewcode-block" id="Target.add_cookie"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.add_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">add_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cookie_dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Adds a cookie in the current (incognito-) context</span>

<span class="sd">        :param cookie_dict: see `Network.CookieParam &lt;https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-CookieParam&gt;`__</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">cookie_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;url&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">cookie_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;domain&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">cookie_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;path&quot;</span><span class="p">)):</span>
            <span class="n">cookie_dict</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_url</span>
        <span class="n">context_id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="c1"># noinspection PyProtectedMember</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_context</span><span class="o">.</span><span class="n">_is_incognito</span><span class="p">:</span>
            <span class="n">context_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">browser_context_id</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">add_cookie</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">cookie_dict</span><span class="o">=</span><span class="n">cookie_dict</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">context_id</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">_document_elem</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">WebElement</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span><span class="p">:</span>
            <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;DOM.getDocument&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;pierce&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span>
            <span class="n">node_id</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;root&quot;</span><span class="p">][</span><span class="s2">&quot;nodeId&quot;</span><span class="p">]</span>
            <span class="n">frame</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_frame</span>
            <span class="n">frame_id</span> <span class="o">=</span> <span class="n">frame</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncWebElement</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">node_id</span><span class="o">=</span><span class="n">node_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                            <span class="n">isolated_exec_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">frame_id</span><span class="o">=</span><span class="n">frame_id</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span> <span class="o">=</span> <span class="k">await</span> <span class="n">WebElement</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">node_id</span><span class="o">=</span><span class="n">node_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                        <span class="n">isolated_exec_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">frame_id</span><span class="o">=</span><span class="n">frame_id</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem_</span>

    <span class="c1"># noinspection PyUnusedLocal</span>
<div class="viewcode-block" id="Target.find_element"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.find_element">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">find_element</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">by</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">WebElement</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;find an element in the current target</span>

<span class="sd">        :param by: one of the locators at :func:`By &lt;selenium_driverless.types.by.By&gt;`</span>
<span class="sd">        :param value: the actual query to find the element by</span>
<span class="sd">        :param timeout: how long to wait for the element to exist</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="n">elem</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">while</span> <span class="ow">not</span> <span class="n">elem</span><span class="p">:</span>
            <span class="n">parent</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">elem</span> <span class="o">=</span> <span class="k">await</span> <span class="n">parent</span><span class="o">.</span><span class="n">find_element</span><span class="p">(</span><span class="n">by</span><span class="o">=</span><span class="n">by</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
            <span class="k">except</span> <span class="p">(</span><span class="n">StaleElementReferenceException</span><span class="p">,</span> <span class="n">NoSuchElementException</span><span class="p">,</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">):</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span>
            <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">timeout</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">timeout</span><span class="p">:</span>
                <span class="k">break</span>
            <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">elem</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">NoSuchElementException</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">elem</span></div>

<div class="viewcode-block" id="Target.find_elements"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.find_elements">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">find_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">by</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">3</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;find multiple elements in the current target</span>

<span class="sd">        :param by: one of the locators at :func:`By &lt;selenium_driverless.types.by.By&gt;`</span>
<span class="sd">        :param value: the actual query to find the elements by</span>
<span class="sd">        :param timeout: how long to wait for not being in a page reload loop in seconds</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
            <span class="n">parent</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="k">await</span> <span class="n">parent</span><span class="o">.</span><span class="n">find_elements</span><span class="p">(</span><span class="n">by</span><span class="o">=</span><span class="n">by</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">)</span>
            <span class="k">except</span> <span class="p">(</span><span class="n">StaleElementReferenceException</span><span class="p">,</span> <span class="n">StaleJSRemoteObjReference</span><span class="p">):</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span>
            <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">timeout</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">timeout</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span>
                    <span class="sa">f</span><span class="s2">&quot;Couldn&#39;t find elements within </span><span class="si">{</span><span class="n">timeout</span><span class="si">}</span><span class="s2"> seconds due to a target reload loop&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.set_source"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.set_source">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">15</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        sets the OuterHtml of the current target (if it has DOM//HTML)</span>

<span class="sd">        :param source: the html</span>
<span class="sd">        :param timeout: the timeout to try setting the source (might fail if the page is in a reload-loop</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timeout</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">document</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>
                <span class="k">await</span> <span class="n">document</span><span class="o">.</span><span class="n">set_source</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
                <span class="k">return</span>
            <span class="k">except</span> <span class="n">StaleElementReferenceException</span><span class="p">:</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_loaded</span><span class="p">()</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t get document element to not be stale&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.search_elements"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.search_elements">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">search_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        query:str | Plain text or query selector or XPath search query.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># ensure DOM is enabled</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dom_enabled</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;DOM.enable&quot;</span><span class="p">)</span>

        <span class="c1"># ensure DOM.getDocument got called</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_document_elem</span>

        <span class="n">elems</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;DOM.performSearch&quot;</span><span class="p">,</span>
                                         <span class="p">{</span><span class="s2">&quot;includeUserAgentShadowDOM&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="s2">&quot;query&quot;</span><span class="p">:</span> <span class="n">query</span><span class="p">})</span>
        <span class="n">search_id</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;searchId&quot;</span><span class="p">]</span>
        <span class="n">elem_count</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;resultCount&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">elem_count</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;DOM.getSearchResults&quot;</span><span class="p">,</span>
                                         <span class="p">{</span><span class="s2">&quot;searchId&quot;</span><span class="p">:</span> <span class="n">search_id</span><span class="p">,</span> <span class="s2">&quot;fromIndex&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;toIndex&quot;</span><span class="p">:</span> <span class="n">elem_count</span><span class="p">})</span>
        <span class="k">for</span> <span class="n">node_id</span> <span class="ow">in</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;nodeIds&quot;</span><span class="p">]:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                <span class="n">elem</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncWebElement</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">node_id</span><span class="o">=</span><span class="n">node_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">isolated_exec_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                            <span class="n">frame_id</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">elem</span> <span class="o">=</span> <span class="k">await</span> <span class="n">WebElement</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">node_id</span><span class="o">=</span><span class="n">node_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">isolated_exec_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                        <span class="n">frame_id</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
            <span class="n">elems</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">elems</span></div>

<div class="viewcode-block" id="Target.get_screenshot_as_file"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_screenshot_as_file">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_screenshot_as_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Saves a screenshot of the current window to a PNG image file.</span>

<span class="sd">        :param filename: The full path.</span>
<span class="sd">            This should end with a `.png` extension.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">str</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;.png&quot;</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;name used for saved screenshot does not match file &quot;</span> <span class="s2">&quot;type. It should end with a `.png` extension&quot;</span><span class="p">,</span>
                <span class="ne">UserWarning</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="n">png</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_screenshot_as_png</span><span class="p">()</span>
        <span class="k">async</span> <span class="k">with</span> <span class="n">aiofiles</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">await</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">png</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.save_screenshot"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.save_screenshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">save_screenshot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;alias to :func: `driver.get_screenshot_as_file &lt;selenium_driverless.webdriver.Chrome.get_screenshot_as_file&gt;`&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_screenshot_as_file</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.get_screenshot_as_png"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_screenshot_as_png">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_screenshot_as_png</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bytes</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the screenshot of the current window as a binary data.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.captureScreenshot&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;format&quot;</span><span class="p">:</span> <span class="s2">&quot;png&quot;</span><span class="p">},</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">b64decode</span><span class="p">(</span><span class="n">res</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;ascii&quot;</span><span class="p">))</span></div>

<div class="viewcode-block" id="Target.snapshot"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.snapshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">snapshot</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;gets the current snapshot as mhtml&quot;&quot;&quot;</span>
        <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Page.captureSnapshot&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">]</span></div>

<div class="viewcode-block" id="Target.save_snapshot"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.save_snapshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">save_snapshot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Saves a snapshot of the current window to a MHTML file.</span>

<span class="sd">        :param filename: The full path you wish to save your snapshot to. This</span>
<span class="sd">                   should end with a ``.mhtml`` extension.</span>

<span class="sd">        .. code-block:: Python</span>

<span class="sd">            await driver.get_snapshot(&#39;snapshot.mhtml&#39;)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">6</span> <span class="ow">or</span> <span class="n">filename</span><span class="p">[</span><span class="o">-</span><span class="mi">6</span><span class="p">:]</span> <span class="o">!=</span> <span class="s2">&quot;.mhtml&quot;</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;name used for saved snapshot does not match file &quot;</span> <span class="s2">&quot;type. It should end with a `.mhtml` extension&quot;</span><span class="p">,</span>
                <span class="ne">UserWarning</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="n">mhtml</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">snapshot</span><span class="p">()</span>
        <span class="k">async</span> <span class="k">with</span> <span class="n">aiofiles</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">await</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">mhtml</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.get_network_conditions"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets Chromium network emulation settings.</span>

<span class="sd">        :Returns:</span>
<span class="sd">            A dict. For example:</span>
<span class="sd">            {&#39;latency&#39;: 4, &#39;download_throughput&#39;: 2, &#39;upload_throughput&#39;: 2,</span>
<span class="sd">            &#39;offline&#39;: False}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;not started with chromedriver&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.set_network_conditions"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.set_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">offline</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">latency</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">download_throughput</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                                     <span class="n">upload_throughput</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                                     <span class="n">connection_type</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span>
                                         <span class="s2">&quot;none&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular2g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular3g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular4g&quot;</span><span class="p">,</span> <span class="s2">&quot;bluetooth&quot;</span><span class="p">,</span> <span class="s2">&quot;ethernet&quot;</span><span class="p">,</span> <span class="s2">&quot;wifi&quot;</span><span class="p">,</span> <span class="s2">&quot;wimax&quot;</span><span class="p">,</span> <span class="s2">&quot;other&quot;</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets Chromium network emulation settings.</span>

<span class="sd">        :Args:</span>
<span class="sd">         - network_conditions: A dict with conditions specification.</span>

<span class="sd">        :Usage:</span>
<span class="sd">            ::</span>

<span class="sd">                target.set_network_conditions(</span>
<span class="sd">                    offline=False,</span>
<span class="sd">                    latency=5,  # additional latency (ms)</span>
<span class="sd">                    download_throughput=500 * 1024,  # maximal throughput</span>
<span class="sd">                    upload_throughput=500 * 1024,  # maximal throughput</span>
<span class="sd">                    connection_type=&quot;wifi&quot;)</span>

<span class="sd">            Note: &#39;throughput&#39; can be used to set both (for download and upload).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;offline&quot;</span><span class="p">:</span> <span class="n">offline</span><span class="p">,</span> <span class="s2">&quot;latency&quot;</span><span class="p">:</span> <span class="n">latency</span><span class="p">,</span>
                <span class="s2">&quot;downloadThroughput&quot;</span><span class="p">:</span> <span class="n">download_throughput</span><span class="p">,</span>
                <span class="s2">&quot;uploadThroughput&quot;</span><span class="p">:</span> <span class="n">upload_throughput</span><span class="p">}</span>

        <span class="n">conn_types</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;none&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular2g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular3g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular4g&quot;</span><span class="p">,</span> <span class="s2">&quot;bluetooth&quot;</span><span class="p">,</span> <span class="s2">&quot;ethernet&quot;</span><span class="p">,</span> <span class="s2">&quot;wifi&quot;</span><span class="p">,</span> <span class="s2">&quot;wimax&quot;</span><span class="p">,</span>
                      <span class="s2">&quot;other&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">connection_type</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">connection_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">conn_types</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;expected </span><span class="si">{</span><span class="n">conn_types</span><span class="si">}</span><span class="s2"> for connection_type,  but got </span><span class="si">{</span><span class="n">connection_type</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;connectionType&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">connection_type</span>

        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Network.emulateNetworkConditions&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.delete_network_conditions"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.delete_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Resets Chromium network emulation settings.&quot;&quot;&quot;</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;not started with chromedriver&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.wait_for_cdp"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.wait_for_cdp">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">wait_for_cdp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        wait for a CDP event and return the data</span>
<span class="sd">        :param event: the name of the event</span>
<span class="sd">        :param timeout: timeout to wait in seconds.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">wait_for</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.add_cdp_listener"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.add_cdp_listener">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">add_cdp_listener</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">callback</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="nb">dict</span><span class="p">],</span> <span class="nb">any</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;add a listener on a CDP event (current target)</span>

<span class="sd">        :param event: the name of the event</span>
<span class="sd">        :param callback: the callback on the event</span>

<span class="sd">        .. note::</span>
<span class="sd">            callback has to accept one parameter (event data as json)</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">add_listener</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="n">event</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.remove_cdp_listener"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.remove_cdp_listener">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">remove_cdp_listener</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">callback</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="nb">dict</span><span class="p">],</span> <span class="nb">any</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        removes the CDP listener</span>
<span class="sd">        :param event: the name of the event</span>
<span class="sd">        :param callback: the callback to remove</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">remove_listener</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="n">event</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.get_cdp_event_iter"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_cdp_event_iter">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cdp_event_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">AsyncIterable</span><span class="p">[</span><span class="nb">dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        iterate over a cdp event</span>

<span class="sd">        :param event: name of the event to iterate over</span>

<span class="sd">        .. code-block:: Python</span>

<span class="sd">            async for data in await target.get_cdp_event_iter(&quot;Page.frameNavigated&quot;):</span>
<span class="sd">                print(data[&quot;frame&quot;][&quot;url&quot;]</span>


<span class="sd">        .. warning::</span>
<span class="sd">            **async only** supported for now</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">method_iterator</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="n">event</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.execute_cdp_cmd"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.execute_cdp_cmd">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_cdp_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmd</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cmd_args</span><span class="p">:</span> <span class="nb">dict</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                              <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Execute Chrome Devtools Protocol command and get returned result The</span>
<span class="sd">        command and command args should follow chrome devtools protocol</span>
<span class="sd">        domains/commands, refer to link</span>
<span class="sd">        https://chromedevtools.github.io/devtools-protocol/</span>

<span class="sd">        :Args:</span>
<span class="sd">         - cmd: A str, command name</span>
<span class="sd">         - cmd_args: A dict, command args. empty dict {} if there is no command args</span>
<span class="sd">        :Usage:</span>
<span class="sd">            ::</span>

<span class="sd">                target.execute_cdp_cmd(&#39;Network.getResponseBody&#39;, {&#39;requestId&#39;: requestId})</span>
<span class="sd">        :Returns:</span>
<span class="sd">            A dict, empty dict {} if there is no result to return.</span>
<span class="sd">            For example to getResponseBody:</span>
<span class="sd">            {&#39;base64Encoded&#39;: False, &#39;body&#39;: &#39;response body string&#39;}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        <span class="n">result</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">socket</span><span class="o">.</span><span class="n">exec</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="n">cmd</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">cmd_args</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cmd</span> <span class="o">==</span> <span class="s2">&quot;Page.enable&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_page_enabled</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">elif</span> <span class="n">cmd</span> <span class="o">==</span> <span class="s2">&quot;Page.disable&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_page_enabled</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">elif</span> <span class="n">cmd</span> <span class="o">==</span> <span class="s2">&quot;DOM.enable&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_dom_enabled</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">elif</span> <span class="n">cmd</span> <span class="o">==</span> <span class="s2">&quot;DOM.disable&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_dom_enabled</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="Target.fetch"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.fetch">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
                    <span class="n">method</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span>
                        <span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="s2">&quot;HEAD&quot;</span><span class="p">,</span> <span class="s2">&quot;PUT&quot;</span><span class="p">,</span> <span class="s2">&quot;DELETE&quot;</span><span class="p">,</span> <span class="s2">&quot;CONNECT&quot;</span><span class="p">,</span> <span class="s2">&quot;OPTIONS&quot;</span><span class="p">,</span> <span class="s2">&quot;TRACE&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;GET&quot;</span><span class="p">,</span>
                    <span class="n">headers</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">body</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bytes</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">mode</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;cors&quot;</span><span class="p">,</span> <span class="s2">&quot;no-cors&quot;</span><span class="p">,</span> <span class="s2">&quot;same-origin&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">credentials</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;omit&quot;</span><span class="p">,</span> <span class="s2">&quot;same-origin&quot;</span><span class="p">,</span> <span class="s2">&quot;include&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">cache</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span>
                        <span class="s2">&quot;default&quot;</span><span class="p">,</span> <span class="s2">&quot;no-store&quot;</span><span class="p">,</span> <span class="s2">&quot;reload&quot;</span><span class="p">,</span> <span class="s2">&quot;no-cache&quot;</span><span class="p">,</span> <span class="s2">&quot;force-cache&quot;</span><span class="p">,</span> <span class="s2">&quot;only-if-cached&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">redirect</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;follow&quot;</span><span class="p">,</span> <span class="s2">&quot;error&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">referrer</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">referrer_policy</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span>
                        <span class="s2">&quot;no-referrer&quot;</span><span class="p">,</span> <span class="s2">&quot;no-referrer-when-downgrade&quot;</span><span class="p">,</span> <span class="s2">&quot;same-origin&quot;</span><span class="p">,</span> <span class="s2">&quot;origin&quot;</span><span class="p">,</span> <span class="s2">&quot;strict-origin&quot;</span><span class="p">,</span> <span class="s2">&quot;origin-when-cross-origin&quot;</span><span class="p">,</span> <span class="s2">&quot;strict-origin-when-cross-origin&quot;</span><span class="p">,</span> <span class="s2">&quot;unsafe-url&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">integrity</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">keepalive</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">priority</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;high&quot;</span><span class="p">,</span> <span class="s2">&quot;low&quot;</span><span class="p">,</span> <span class="s2">&quot;auto&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;high&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">20</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        executes a JS ``fetch`` request within the target,</span>
<span class="sd">        see `developer.mozilla.org/en-US/docs/Web/API/fetch &lt;https://developer.mozilla.org/en-US/docs/Web/API/fetch&gt;`_ for reference</span>

<span class="sd">        returns smth like</span>

<span class="sd">        .. code-block:: Python</span>

<span class="sd">            {</span>
<span class="sd">                &quot;body&quot;:bytes,</span>
<span class="sd">                &quot;headers&quot;:dict,</span>
<span class="sd">                &quot;ok&quot;:bool,</span>
<span class="sd">                &quot;status_code&quot;:int,</span>
<span class="sd">                &quot;redirected&quot;:bool,</span>
<span class="sd">                &quot;status_text&quot;:str,</span>
<span class="sd">                &quot;type&quot;:str,</span>
<span class="sd">                &quot;url&quot;:str</span>
<span class="sd">            }</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">body</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">body</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">body</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
        <span class="n">options</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">method</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;method&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">method</span>
        <span class="k">if</span> <span class="n">headers</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;headers&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">headers</span>
        <span class="k">if</span> <span class="n">body</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;body&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">base64</span><span class="o">.</span><span class="n">b64encode</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;ascii&quot;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mode</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mode</span>
        <span class="k">if</span> <span class="n">credentials</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;credentials&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">credentials</span>
        <span class="k">if</span> <span class="n">cache</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;cache&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cache</span>
        <span class="k">if</span> <span class="n">redirect</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;redirect&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">redirect</span>
        <span class="k">if</span> <span class="n">referrer</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;referrer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">referrer</span>
        <span class="k">if</span> <span class="n">referrer_policy</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;referrerPolicy&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">referrer_policy</span>
        <span class="k">if</span> <span class="n">integrity</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;integrity&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">integrity</span>
        <span class="k">if</span> <span class="n">keepalive</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;keepalive&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">keepalive</span>
        <span class="k">if</span> <span class="n">priority</span><span class="p">:</span>
            <span class="n">options</span><span class="p">[</span><span class="s2">&quot;priority&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">priority</span>

        <span class="n">script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">            async function bufferTobase64(array) {</span>
<span class="s2">              return new Promise((resolve) =&gt; {</span>
<span class="s2">                const blob = new Blob([array]);</span>
<span class="s2">                const reader = new FileReader();</span>
<span class="s2">                </span>
<span class="s2">                reader.onload = (event) =&gt; {</span>
<span class="s2">                  const dataUrl = event.target.result;</span>
<span class="s2">                  const [_, base64] = dataUrl.split(&#39;,&#39;);</span>
<span class="s2">                  </span>
<span class="s2">                  resolve(base64);</span>
<span class="s2">                };</span>
<span class="s2">                </span>
<span class="s2">                reader.readAsDataURL(blob);</span>
<span class="s2">              });</span>
<span class="s2">            };</span>
<span class="s2">            async function base64ToBuffer(base64) {</span>
<span class="s2">              const dataUrl = &quot;data:application/octet-binary;base64,&quot; + base64;</span>
<span class="s2">            </span>
<span class="s2">              const res = await fetch(dataUrl)</span>
<span class="s2">              return await res.arrayBuffer()</span>
<span class="s2">            };</span>

<span class="s2">            function headers2dict(headers){</span>
<span class="s2">                var my_dict = </span><span class="si">{}</span><span class="s2">;</span>
<span class="s2">                for (var pair of headers.entries()) {</span>
<span class="s2">                        my_dict[pair[0]] = pair[1]};</span>
<span class="s2">                return my_dict}</span>

<span class="s2">            async function get(url, options){</span>
<span class="s2">                if(options.body){options.body = await base64ToBuffer(options.body)}</span>
<span class="s2">                var response = await fetch(url, options);</span>
<span class="s2">                var buffer = await response.arrayBuffer()</span>
<span class="s2">                var b64 = await bufferTobase64(buffer)</span>
<span class="s2">                var res = {</span>
<span class="s2">                        &quot;b64&quot;:b64,</span>
<span class="s2">                        &quot;headers&quot;:headers2dict(response.headers),</span>
<span class="s2">                        &quot;ok&quot;:response.ok,</span>
<span class="s2">                        &quot;status_code&quot;:response.status,</span>
<span class="s2">                        &quot;redirected&quot;:response.redirected,</span>
<span class="s2">                        &quot;status_text&quot;:response.statusText,</span>
<span class="s2">                        &quot;type&quot;:response.type,</span>
<span class="s2">                        &quot;url&quot;:response.url</span>
<span class="s2">                        };</span>
<span class="s2">                return res;</span>
<span class="s2">            }</span>
<span class="s2">            return await get(arguments[0], arguments[1])</span>
<span class="s2">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
        <span class="n">result</span><span class="p">[</span><span class="s2">&quot;body&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">base64</span><span class="o">.</span><span class="n">b64decode</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;b64&quot;</span><span class="p">])</span>
        <span class="k">del</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;b64&quot;</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="Target.xhr"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.xhr">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">xhr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
                  <span class="n">method</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="s2">&quot;PUT&quot;</span><span class="p">,</span> <span class="s2">&quot;DELETE&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;GET&quot;</span><span class="p">,</span>
                  <span class="n">body</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bytes</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                  <span class="n">user</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">password</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">with_credentials</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">mime_type</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;text/plain&quot;</span><span class="p">,</span>
                  <span class="n">extra_headers</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                  <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        executes a JS ``XMLHttpRequest`` request within the target,</span>
<span class="sd">        see `developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest &lt;https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest&gt;`_ for reference</span>

<span class="sd">        :param url: the url to get</span>
<span class="sd">        :param method: one of &quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;, &quot;DELETE&quot;</span>
<span class="sd">        :param body: body to send with a request</span>
<span class="sd">        :param user: user to authenticate with</span>
<span class="sd">        :param password: password to authenticate with</span>
<span class="sd">        :param with_credentials: whether to include cookies</span>
<span class="sd">        :param mime_type: the type to parse the response as</span>
<span class="sd">        :param extra_headers: a key/value dict of extra headers to add to the request</span>
<span class="sd">        :param timeout: timeout in seconds for the request to take</span>

<span class="sd">        returns smth like</span>

<span class="sd">        .. code-block:: Python</span>

<span class="sd">            {</span>
<span class="sd">                &quot;status&quot;: int,</span>
<span class="sd">                &quot;response&quot;: any,</span>
<span class="sd">                &quot;responseText&quot;:str,</span>
<span class="sd">                &quot;responseType&quot;:str,</span>
<span class="sd">                &quot;responseURL&quot;:str,</span>
<span class="sd">                &quot;responseXML&quot;:any,</span>
<span class="sd">                &quot;statusText&quot;:str,</span>
<span class="sd">                &quot;responseHeaders&quot;:dict</span>
<span class="sd">            }</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">extra_headers</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">extra_headers</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">body</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">body</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">body</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">body</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">body</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">base64</span><span class="o">.</span><span class="n">b64encode</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;ascii&quot;</span><span class="p">))</span>
        <span class="n">script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">        async function base64ToBuffer(base64) {</span>
<span class="s2">              const dataUrl = &quot;data:application/octet-binary;base64,&quot; + base64;</span>
<span class="s2">            </span>
<span class="s2">              const res = await fetch(dataUrl)</span>
<span class="s2">              return await res.arrayBuffer()</span>
<span class="s2">        };</span>
<span class="s2">        async function makeRequest(withCredentials, mimeType, extraHeaders, method, url, user, password, body) {</span>
<span class="s2">            let xhr = new XMLHttpRequest();</span>

<span class="s2">            if(!user){user = null};</span>
<span class="s2">            if(!password){password = null};</span>
<span class="s2">            if(!body){body = null}else{body = await base64ToBuffer(body)};</span>
<span class="s2">            xhr.overrideMimeType(mimeType);</span>

<span class="s2">            xhr.open(method, url, true, user, password);</span>
<span class="s2">            Object.keys(extraHeaders).forEach((key) =&gt; {</span>
<span class="s2">                xhr.setRequestHeader(key, extraHeaders[key])</span>
<span class="s2">            });</span>
<span class="s2">            xhr.withCredentials = withCredentials;</span>
<span class="s2">            const promise = new Promise((resolve, reject) =&gt; {</span>
<span class="s2">                xhr.onload = () =&gt; {resolve(xhr)};</span>
<span class="s2">                xhr.onerror = () =&gt; {reject(new Error(&quot;XHR failed&quot;))};</span>
<span class="s2">            });</span>
<span class="s2">            xhr.send(body);</span>
<span class="s2">            return await promise</span>
<span class="s2">        };</span>
<span class="s2">        var xhr =  await makeRequest(...arguments);</span>
<span class="s2">        data = {</span>
<span class="s2">            status: xhr.status,</span>
<span class="s2">            response: xhr.response,</span>
<span class="s2">            responseText:xhr.responseText,</span>
<span class="s2">            responseType:xhr.responseType,</span>
<span class="s2">            responseURL:xhr.responseURL,</span>
<span class="s2">            responseXML:xhr.responseXML,</span>
<span class="s2">            statusText:xhr.statusText,</span>
<span class="s2">            responseHeaders:xhr.getAllResponseHeaders()</span>

<span class="s2">        };</span>
<span class="s2">        return data</span>
<span class="s2">        &quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="n">with_credentials</span><span class="p">,</span> <span class="n">mime_type</span><span class="p">,</span>
                                     <span class="n">extra_headers</span><span class="p">,</span> <span class="n">method</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span>
                                     <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># parse headers</span>
        <span class="n">headers</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;responseHeaders&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">headers</span> <span class="o">==</span> <span class="s2">&quot;null&quot;</span><span class="p">:</span>
            <span class="n">_headers</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">headers</span> <span class="o">=</span> <span class="n">headers</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\r\n</span><span class="s2">&quot;</span><span class="p">)</span>
            <span class="n">_headers</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">header</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span>
                <span class="n">header</span> <span class="o">=</span> <span class="n">header</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;: &#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">header</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">header</span>
                    <span class="n">_headers</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="n">data</span><span class="p">[</span><span class="s1">&#39;responseHeaders&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_headers</span>

        <span class="c1"># todo: parse different response types</span>
        <span class="k">return</span> <span class="n">data</span></div>

    <span class="c1"># noinspection PyTypeChecker</span>
<div class="viewcode-block" id="Target.get_sinks"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_sinks">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_sinks</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :Returns: A list of sinks available for Cast.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Cast.enable&quot;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;not started with chromedriver&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.get_issue_message"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.get_issue_message">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_issue_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :Returns: An error message when there is any issue in a Cast session.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;not started with chromedriver&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Target.set_sink_to_use"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.set_sink_to_use">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_sink_to_use</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets a specific sink, using its name, as a Cast session receiver</span>
<span class="sd">        target.</span>

<span class="sd">        :Args:</span>
<span class="sd">         - sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Cast.setSinkToUse&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;sinkName&quot;</span><span class="p">:</span> <span class="n">sink_name</span><span class="p">})</span></div>

<div class="viewcode-block" id="Target.start_desktop_mirroring"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.start_desktop_mirroring">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">start_desktop_mirroring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Starts a desktop mirroring session on a specific receiver target.</span>

<span class="sd">        :Args:</span>
<span class="sd">         - sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Cast.startDesktopMirrorin&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;sinkName&quot;</span><span class="p">:</span> <span class="n">sink_name</span><span class="p">})</span></div>

<div class="viewcode-block" id="Target.start_tab_mirroring"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.start_tab_mirroring">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">start_tab_mirroring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Starts a tab mirroring session on a specific receiver target.</span>

<span class="sd">        :param sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Cast.startTabMirroring&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;sinkName&quot;</span><span class="p">:</span> <span class="n">sink_name</span><span class="p">})</span></div>

<div class="viewcode-block" id="Target.stop_casting"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.Target.stop_casting">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">stop_casting</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Stops the existing Cast session on a specific receiver target.</span>

<span class="sd">        :param sink_name: Name of the sink to stop the Cast session.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Cast.stopCasting&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;sinkName&quot;</span><span class="p">:</span> <span class="n">sink_name</span><span class="p">})</span></div></div>


<div class="viewcode-block" id="TargetInfo"><a class="viewcode-back" href="../../../api/Target.html#selenium_driverless.types.target.TargetInfo">[docs]</a><span class="k">class</span> <span class="nc">TargetInfo</span><span class="p">:</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Info for a Target</span>

<span class="sd">    .. note::</span>

<span class="sd">        the infos are not dynamic</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_info</span><span class="p">:</span> <span class="nb">dict</span><span class="p">,</span> <span class="n">target_getter</span><span class="p">:</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">Future</span> <span class="ow">or</span> <span class="n">Target</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;targetId&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_type</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_title</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;title&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;url&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_attached</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;attached&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_opener_id</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;openerId&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_can_access_opener</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;canAccessOpener&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_opener_frame_id</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;openerFrameId&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_browser_context_id</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;browserContextId&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_subtype</span> <span class="o">=</span> <span class="n">target_info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;subtype&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_target</span> <span class="o">=</span> <span class="n">target_getter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_started</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="fm">__await__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span><span class="o">.</span><span class="fm">__await__</span><span class="p">()</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_init</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_started</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="c1"># noinspection PyPep8Naming</span>
    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">Target</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        the Target itself</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_target</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;the ``Target.TargetID``&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_type</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">title</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_title</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_url</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">attached</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Whether the target has an attached client.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_attached</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">opener_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Opener ``Target.TargetId``&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_opener_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">can_access_opener</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Whether the target has access to the originating window.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_can_access_opener</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">opener_frame_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;``Page.FrameId`` of originating window (is only set if target has an opener).&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_opener_frame_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">browser_context_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;``Browser.BrowserContextID``&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_browser_context_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">subtype</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Provides additional details for specific target types. For example, for the type of &quot;page&quot;, this may be set to &quot;portal&quot; or &quot;prerender&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_subtype</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s1">(type=&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="si">}</span><span class="s1">&quot;,title=&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">title</span><span class="si">}</span><span class="s1">)&quot;&#39;</span></div>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2024, Aurin Aegerter (aka Steve, kaliiiiiiiiii).</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>